// 模拟延迟
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms))

// 模拟用户数据
const mockUsers = [
  {
    userID: 1,
    name: '张三',
    email: 'zhangsan@example.com',
    isVIP: 1,
    isFrozen: 0,
    role: [1, 2]
  },
  {
    userID: 2,
    name: '李四',
    email: 'lisi@example.com',
    isVIP: 0,
    isFrozen: 1,
    role: [1]
  },
  {
    userID: 3,
    name: '王五',
    email: 'wangwu@example.com',
    isVIP: 1,
    isFrozen: 0,
    role: [1, 2, 3]
  },
  {
    userID: 4,
    name: '赵六',
    email: 'zhaoliu@example.com',
    isVIP: 0,
    isFrozen: 0,
    role: [1]
  }
]

// 模拟课程数据
const mockCourses = [
  {
    courseID: 1,
    name: 'Vue3 入门到精通',
    desc: 'Vue3 框架的完整学习课程',
    price: 199,
    img: 'https://example.com/vue3.jpg',
    category: '前端开发',
    teacher: '张老师',
    productID: 'P001'
  },
  {
    courseID: 2,
    name: 'Node.js 实战',
    desc: 'Node.js 后端开发实战课程',
    price: 299,
    img: 'https://example.com/nodejs.jpg',
    category: '后端开发',
    teacher: '李老师',
    productID: 'P002'
  }
]

// 模拟统计数据
const mockStatistics = [
  { category: '前端', totalCourses: 12 },
  { category: '后端', totalCourses: 8 },
  { category: 'AI', totalCourses: 5 },
  { category: '移动开发', totalCourses: 6 }
]

const mockWatchCount = [
  { chapter: 'Vue3入门', views: 120 },
  { chapter: 'Node实战', views: 80 },
  { chapter: 'React基础', views: 150 },
  { chapter: 'Python入门', views: 200 }
]

// Mock API 响应
export const mockApi = {
  // 用户相关
  async getUserList({ page = 1, pageSize = 10, search = '' }) {
    await delay(500) // 模拟网络延迟
    let filteredUsers = mockUsers
    if (search) {
      filteredUsers = mockUsers.filter(user => 
        user.name.includes(search) || user.email.includes(search)
      )
    }
    const start = (page - 1) * pageSize
    const end = start + pageSize
    return {
      code: 1,
      message: 'success',
      data: {
        items: filteredUsers.slice(start, end),
        total: filteredUsers.length,
        page,
        pageSize
      }
    }
  },

  async freezeUser(userId) {
    await delay(300)
    const user = mockUsers.find(u => u.userID === userId)
    if (user) {
      user.isFrozen = 1
    }
    return {
      code: 1,
      message: '冻结成功',
      data: null
    }
  },

  async unfreezeUser(userId) {
    await delay(300)
    const user = mockUsers.find(u => u.userID === userId)
    if (user) {
      user.isFrozen = 0
    }
    return {
      code: 1,
      message: '解冻成功',
      data: null
    }
  },

  // 课程相关
  async getCourseList({ page = 1, pageSize = 10 }) {
    await delay(500)
    const start = (page - 1) * pageSize
    const end = start + pageSize
    return {
      code: 1,
      message: 'success',
      data: {
        items: mockCourses.slice(start, end),
        total: mockCourses.length,
        page,
        pageSize
      }
    }
  },

  // 统计相关
  async getCourseStatistics() {
    await delay(500)
    return {
      code: 1,
      message: 'success',
      data: {
        items: mockStatistics
      }
    }
  },

  async getCourseWatchCount() {
    await delay(500)
    return {
      code: 1,
      message: 'success',
      data: {
        items: mockWatchCount
      }
    }
  }
} 